<!DOCTYPE html>
<html>
<head>
<include file="Include:meta" />
<title>任务管理-目的地运营集团数据管理平台</title>
<include file="Include:style" />
<link rel="stylesheet" href="__PUBLIC__/mobile/css/mobiscroll.min.css">
</head>
<body style="background: #f3f3f3;">
<div class="header">
    <a class="back_btn" href="javascript:history.back(-1);"></a>
	新增任务单
</div>
<div class="content">
    <div class="communicate_add">
		<form name='number_validate'>
			<input type="hidden" name="pid" value="{$project['id']}">
			<input type="hidden" name="id" value="{$project_bg['id']}">
			<div class="form_item">
				<div class="form_item_tit">
					任务信息
				</div>
				<div class="form_item_box">
					<ul class="choice_list">
                        <li class="tz_li select_li">
                            <select id="type1" name="type1">
                                <option value="-10">请填写任务分类…</option>
								<foreach name="type1_list" item="vo">
                                <option value="{$vo['id']}">{$vo['first_name']}</option>
								</foreach>
                            </select>
                            <input type="hidden" class="vinp">
                            <div class="fix_inp">
                                <input type="text" class="other" name="type1_other">
                                <a class="close first_close" href="javascript:;"></a>
                            </div>
                        </li>
                        <li class="tz_li select_li">
                            <select id="type2" name="type2">
                                <option value="-10">请先选择任务分类…</option>
                            </select>
                            <input type="hidden" class="vinp">
                            <div class="fix_inp">
                                <input type="text" class="other" name="type2_other">
                                <a class="close" href="javascript:;"></a>
                            </div>
                        </li>
                        <li class="xm_li select_li">
                            <select id="type3" name="type3">
                                <option value="-10">请先选择任务子类…</option>
                            </select>
                            <input type="hidden" class="vinp">
                            <div class="fix_inp">
                                <input type="text" class="other" name="type3_other">
                                <a class="close" href="javascript:;"></a>
                            </div>
						</li>
                        <li class="task_li">
							<input class="text_input" name="name" type="text" placeholder="请填写任务名称…">
						</li>
						<li class="name_li">
							<input id="name" class="text_input" name="head_name" type="text" mid="" readonly placeholder="请选择任务负责人…">
						</li>
						<li class="data_li">
							<input id="start_date" class="text_input" name="start_date" type="text" readonly placeholder="请选择任务开始日期…">
                        </li>
                        <li class="data_li">
							<input id="end_date" class="text_input" name="end_date" type="text" readonly placeholder="请选择任务结束日期…">
						</li>
					</ul>
				</div>
				<div class="form_item_tit">
					任务说明
				</div>
				<div class="form_item_box label_box">
					<textarea name="remark" placeholder="点击填写任务说明…"></textarea>
				</div>
				<div class="build_btn paddbox"><div><button type="button" class="sub_btn main_sub">提 交</button></div></div>
			</div>
		</form>
    </div>
</div>
<include file="Include:javascript" />
<script src="__PUBLIC__/mobile/js/mobiscroll.min.js"></script>
<script>
    var provinces = {$user_list};
    $(function(){
        //任务分类
        $('#type1').mobiscroll().select({
            theme: 'ios',
            lang: 'zh',
            display: 'bottom'
        });
        $('#type2').mobiscroll().select({
            theme: 'ios',
            lang: 'zh',
            display: 'bottom'
        });
        $('#type3').mobiscroll().select({
            theme: 'ios',
            lang: 'zh',
            display: 'bottom'
        });
        $('.first_close').click(function(){
            $('.fix_inp').hide().find('input').val('');
            $("[name='type2']").html("<option value='-10' selected>请先选择任务分类…</option>").trigger('change');
            $("[name='type3']").html("<option value='-10' selected>请先选择任务子类…</option>").trigger('change');
            $('#type2').mobiscroll().select({
                theme: 'ios',
                lang: 'zh',
                display: 'bottom'
            });
            $('#type3').mobiscroll().select({
                theme: 'ios',
                lang: 'zh',
                display: 'bottom'
            });
        })
        $("[name='type1']").change(function(){
            var val = $(this).val();
            if(val==-10){
                $("[name='type2']").html("<option value='-10' selected>请先选择任务分类…</option>").trigger('change');
                $('#type2').mobiscroll().select({
                    theme: 'ios',
                    lang: 'zh',
                    display: 'bottom'
                });
            }else{
                $.ajax({
                    type:"POST",
                    async:false,
                    dataType:"json",
                    data:{"type1":val,"action":"type2_list"},
                    url:"/dms_erp/index.php?s=/Mobile/Project/task_ajax",
                    success:function(data){
                        if(data.status){
                            var option = "<option value='-10' selected>请选择任务子类</option>";
                            for(var i=0;i<data.data.length;i++){
                                option+="<option value="+data.data[i].id+">"+data.data[i].second_name+"</option>";
                            }
                            $("[name='type2']").html(option).trigger('change');
                            $('#type2').mobiscroll().select({
                                theme: 'ios',
                                lang: 'zh',
                                display: 'bottom'
                            });
                            $("[name='type3']").html("<option value='-10' selected>请先选择任务子类…</option>").trigger('change');
                            $('#type3').mobiscroll().select({
                                theme: 'ios',
                                lang: 'zh',
                                display: 'bottom'
                            });
                        }else{
                            $("[name='type2']").html("<option value='-10' selected>请先选择任务分类…</option>").trigger('change')
                        }
                    }
                });
            }
        })

        //子类
        $("[name='type2']").change(function(){
            var val = $("[name='type1']").val(),
                val2 = $(this).val();
            if(val==-10){
                $("[name='type3']").html("<option value='-10' selected>请先选择任务子类…</option>").trigger('change');
                $('#type3').mobiscroll().select({
                    theme: 'ios',
                    lang: 'zh',
                    display: 'bottom'
                });
            }else{
                $.ajax({
                    type:"POST",
                    async:false,
                    dataType:"json",
                    data:{"type1":val,"type2":val2,"action":"type3_list"},
                    url:"/dms_erp/index.php?s=/Mobile/Project/task_ajax",
                    success:function(data){
                        if(data.status){
                            var option = "<option value='-10' selected>请选择任务明细</option>";
                            for(var i=0;i<data.data.length;i++){
                                option+="<option value="+data.data[i].id+">"+data.data[i].third_name+"</option>";
                            }
                            $("[name='type3']").html(option).trigger('change');
                            $('#type3').mobiscroll().select({
                                theme: 'ios',
                                lang: 'zh',
                                display: 'bottom'
                            });
                        }else{
                            $("[name='type3']").html("<option value='-10' selected>请先选择任务子类…</option>").trigger('change')
                        }
                    }
                });
            }
        })

        $('.select_li').each(function(){
            var _this = $(this);
            _this.find('select').change(function(){
                var val = _this.find('select').val();
                _this.find('.vinp').val(val);
                if(val==75 || val==161 || val==563){
                    _this.find('.fix_inp').show().find('input').focus();
                    _this.find('.fix_inp').find('input').focus();
                }
            })
        })
        $('.fix_inp .close').click(function(){
            $(this).parents('.fix_inp').hide();
            $(this).parents('.fix_inp').siblings('select').find('option[value=-10]').attr("selected", true);
            var txt = $(this).parents('.fix_inp').siblings('select').find('option[value=-10]').text();
            $(this).parents('.fix_inp').siblings('.mbsc-control').attr('value',txt);
            $(this).parents('.fix_inp').siblings('.vinp').val('');
            $(this).siblings('.other').val('');
            $(this).parents('.fix_inp').siblings('select').mobiscroll().select({
                theme: 'ios',
                lang: 'zh',
                display: 'bottom'
            });

        })
        $("#name").CityPicker();
		$("[name='start_date'],[name='end_date'],[name='head_name']").change(function(){
            submit();
        })
        $('.mbsc-comp').change(function(){
            if($(this).val()!=-10){
                submit();
            }
        })
        $("[name='start_date']").change(function(){
            $("[name='end_date']").val('');
        })
        $("[name='remark'],.other,.text_input").blur(function(){
            submit();
        })
        $("[name='type3']").change(function(){
            var val = $(this).val();
            submit();
            if(val==161){
                $('.choice_list').addClass('active');
            }else{
                $('.choice_list').removeClass('active');
            }
        })
        var calendar1 = $('#start_date').mobiscroll().date({
            theme: 'ios',
            lang: 'zh',
            display: 'bottom',
            onSet: function (event, inst) {
                var datav = $(this).val(),
                    year = datav.substring(0,4),
                    month = datav.substring(5,7),
                    day = datav.substring(8,10),
                mins = new Date(year,month-1,day);
                var calendar2 = $('#end_date').mobiscroll().date({
                    theme: 'ios',
                    lang: 'zh',
                    display: 'bottom',
                    min: mins
                })
            }
        });
		submit();
		//提交
		$('.main_sub').click(function(){
            var fid = $('.tz_li input').attr('fid'),
                mid = $("[name='head_name']").attr('mid');
            $.ajax({
                type:"POST",
                async:false,
                dataType:"json",
                data:$("[name='number_validate']").serialize()+"&fid="+fid+"&head_uid="+mid+"&action=add_task",
                url:"__APP__/Mobile/Project/task_ajax",
                success:function(data){
                    success_pop(data.status,data.msg,1,"__APP__/Mobile/Project/task_list/pid/{$pid}");
                }
            });
        })
    })
    //提交
    function submit(){
		var tag = true;
		$('.text_input').each(function(){
			if($(this).val()==''){
				tag = false;
				$('.sub_btn').addClass('disabled').attr('disabled',true);
			}
		})
        $('.select_li').each(function(){
            if($(this).find('select').val()==-10){
                tag = false;
                $('.sub_btn').addClass('disabled').attr('disabled',true);
            }
        })
        $('.active .other').each(function(){
            if($(this).val()==''){
                tag = false;
                $('.sub_btn').addClass('disabled').attr('disabled',true);
            }
        })
        if($("[name='remark']").val()==''){
            tag = false;
            $('.sub_btn').addClass('disabled').attr('disabled',true);
        }
        if(tag){
            $('.sub_btn').removeClass('disabled').attr('disabled',false);
        }
    }
    function bg_che(){
        $('.bg_li p').hide();
		var val_arr=$("[name='name']").val().split('【');
		var	val=val_arr[0],
            mid = $("[name='name']").attr('mid');
        $('.bg_li').addClass('active').find('.span').append("<span><a href='javascript:;'></a><input type='text' readonly value='"+val+"''><input name='hide_val[]' type='hidden' value='"+mid+"'></span>");
    }
    function remove(){
        $('.picker_tit').html('<a class="back_btn" href="javascript:;"></a>选择任务负责人')
    }
</script>
<script src="__PUBLIC__/mobile/js/cityPicker.js"></script>
</body>
</html>